<template>
  <div class='searchHistory-container'>
    <van-cell title="搜索历史">
      <span v-if="isDeleteShow" @click="$emit('all-delete')">全部删除</span>
      <span style="color: #ccc; padding: 0 10px" v-if="isDeleteShow">|</span>
      <span style="color: red;" v-if="isDeleteShow" @click="isDeleteShow = false">完成</span>
      <van-icon name="delete" v-if="!isDeleteShow" @click="isDeleteShow = !isDeleteShow" />
    </van-cell>
    <van-cell :title="item" v-for="(item, index) in searchHistories" :key="index"
      @click="clearHistory(index, item)">
      <van-icon name="clear" v-if="isDeleteShow" />
      <van-icon name="arrow" v-else />
    </van-cell>
  </div>
</template>
<script>
export default {
  name: 'searchHistoryPage',
  components: {},
  props: {
    // 搜索历史列表
    searchHistories: {
      type: Array,
      require: true,
    },
  },
  data() {
    return {
      isDeleteShow: false, // 删除状态
    };
  },
  created() {},
  computed: {},
  methods: {
    clearHistory(index, item) {
      // 如果是删除状态 删除历史记录
      if(this.isDeleteShow) {
        this.searchHistories.splice(index, 1)
      }else {
        // 非删除状态 跳转到该搜索项
        this.$emit('search-text', item)
      }
    }
  },
};
</script>
<style lang='less' scoped>
</style>
